<?php

define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('view.php');
require_once('form/elements/viewchooser.php');

$extradata = json_decode(param_variable('extradata'));

safe_require('blocktype', $extradata->blocktype);
$data = PieformElementViewchooser::set_attributes(
    call_static_method(generate_class_name('blocktype', $extradata->blocktype), 'viewchooser_element', $extradata->value)
);
$data['offset'] = param_integer('offset', 0);
//$data['blocktype'] = $extradata->blocktype;

list($html, $pagination, $count, $offset) = PieformElementViewchooser::build_data($data);

json_reply(false, array(
    'message' => null,
    'data' => array(
        'tablerows' => $html,
        'pagination' => $pagination['html'],
        'pagination_js' => $pagination['javascript'],
        'count' => $count,
        'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')),
        'offset' => $offset,
    )
));

?>
